﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.BlackApart.Business.Prices {
    public class ImpPriceRabat : IPriceRabat {

        #region Fields

        internal Dictionary<string, IPriceRabat> rabats;

        #endregion

        #region Properties

        public string RabatKey { get; set; }
        public string RabatName { get; set; }
        public float RabatValue { get; set; }
        public bool HaveRabats { get { return rabats != null; } }
        public bool RabatHasBeenOverridden { get; private set; }

        #endregion

        #region Methods

        public void SetRabats(IPriceRabat[] rabats) {
            Dictionary<string, IPriceRabat> rr = new Dictionary<string, IPriceRabat>();
            foreach (IPriceRabat rabat in rabats)
                rr.Add(rabat.RabatKey, rabat);
            this.rabats = rr;
        }

        public IPriceRabat GetRabat(string rabatKey) {
            if (this.HaveRabats && this.rabats.ContainsKey(rabatKey))
                return this.rabats[rabatKey];
            else
                return null;
        }

        public void OverrideRabatValue(float rabatValue) {
            this.RabatValue = rabatValue;
            this.RabatHasBeenOverridden = true;
        }

        #endregion

    }
}
